package com.itgo.codegen.util;

import java.util.List;

import com.itgo.codegen.bean.ColumnMeta;
import com.itgo.codegen.bean.TableMeta;
import com.itgo.codegen.config.Config;

public class DBMetaUtil {
	
	public static List<ColumnMeta> getColumnMeta( String tableName , String dbName ){
		String sql = "SELECT column_name , data_type , column_comment , column_key FROM information_schema.columns WHERE table_name = ? AND table_schema= ? " ;
		List<ColumnMeta> dataMetas = DbHelper.queryList( sql , ColumnMeta.class ,  tableName , dbName ) ;
		return dataMetas ;
	}
	
	public static TableMeta getTableMeta(){
		TableMeta tableMeta = new TableMeta() ;
		tableMeta.setTableName( Config.tableName );
		tableMeta.setTableAliasName( Config.tableAliasName );
		tableMeta.setColumnMetas( getColumnMeta( Config.tableName , Config.dbName ) );
		return tableMeta ;
	}
	
}
